import { connect } from "react-redux";
import actions from "../../store/action/index";
import Link from "./Link";
// ownProps（可选）就是传过来的组件props。当接收到新的props时又会重新调用。
const mapStateToProps = (state, ownProps) => {
  return {
    active: ownProps.filter === state.visibilityFilter,
  };
};

const mapDispatchToProps = (dispatch, ownProps) => {
  return {
    onClick: () => {
      dispatch(actions.setVisibilityFilter(ownProps.filter));
    },
  };
};

const FilterLink = connect(mapStateToProps, mapDispatchToProps)(Link);

export default FilterLink;
